package com.jk.service;

import com.jk.dao.BankCardDao;
import com.jk.dao.PersonalDataDao;
import com.jk.dao.UserDao;
import com.jk.entity.BankCardEntity;
import com.jk.entity.PersonalDataEntity;
import com.jk.pojo.UserBean;
import com.jk.utils.Base64Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 位佳生
 * @title: QueryInterfaceService
 * @projectName springboot_financial
 * @description: TODO
 * @date 2022/11/919:01
 */
@Service
public class QueryInterfaceService {

    @Autowired
    private UserDao userDao;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private PersonalDataDao personalDataDao;
    @Autowired
    private BankCardDao bankCardDao;


    public Boolean queryUserCard() {
        UserBean userBean = (UserBean) redisTemplate.opsForValue().get("denglu");
        UserBean user = userDao.getPhone(userBean.getUser_phone());
        if (user.getUser_idcard() != null&&user.getUser_idcard() !="" && Base64Utils.decodeData(user.getUser_idcard()).length() ==18){
            return true;
        }
        else {
            return false;
        }
    }

    public Boolean queryUserPwd() {
        UserBean userBean = (UserBean) redisTemplate.opsForValue().get("denglu");
        UserBean user = userDao.getPhone(userBean.getUser_phone());
        if (user.getUser_pwd() != null&&user.getUser_pwd() !=""){
            return true;
        }
        else {
            return false;
        }
    }

    public Boolean queryUserBox() {
        UserBean userBean = (UserBean) redisTemplate.opsForValue().get("denglu");
        try {
            PersonalDataEntity personalDataEntity = personalDataDao.selectById(userBean.getUser_id());
            if (!personalDataEntity.getPersonal_data_e_mail().equals(null) && !personalDataEntity.getPersonal_data_e_mail().equals("")){
                  return true;
            }else {
                return false;
            }
        }catch (Exception e){
            e.getMessage();
            return true;
        }
    }


    public Boolean queryUserWith() {
        UserBean userBean = (UserBean) redisTemplate.opsForValue().get("denglu");
        UserBean user = userDao.getPhone(userBean.getUser_phone());
        if (user.getUser_with() == null || user.getUser_with() == "" || user.getUser_with().length() == 0){
            return true;
        }
        else {
            return false;
        }
    }


    public Boolean queryUserPhone() {
        UserBean userBean = (UserBean) redisTemplate.opsForValue().get("denglu");
        UserBean user = userDao.getPhone(userBean.getUser_phone());
        if (user.getUser_phone().equals(null)&&user.getUser_phone().equals("")){
            return true;
        }
        else {
            return false;
        }
    }

    public Boolean queryUserBankCard() {
        UserBean userBean = (UserBean) redisTemplate.opsForValue().get("denglu");
        try {
            List<BankCardEntity> bankCardEntity = bankCardDao.selectBankCardById(userBean.getUser_phone());
                if (!bankCardEntity.equals(null) && !bankCardEntity.equals("") && bankCardEntity.size() >0){
                    return true;
                }else {
                    return false;
                }
        }catch (Exception e){
            e.getMessage();
            return true;
        }
    }
}
